<template>
	<userinfo class="userinfo-box" :options="user_options" @getUserscope="getUserInfo" @toLogin="getUserInfo"></userinfo>
</template>

<script>
var _this;
var app = getApp();
import common from '../../utils/common.js'
const reportLoginStatus = (msg, back) => {
  var param = {
    id: _this.loginId,
    msg: JSON.stringify(msg)
  };
  common.post('Event_way&a=up', param, function (data) {
    if (!back) {
      uni.navigateBack();
    }
  });
};

export default {
  data() {
    return {
      userInfo: '',
      loginId: '',
	  user_options: {}
    };
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if (!_this.userInfo) {
      var msg = {
        desc: '小程序授权登录失败'
      };
      reportLoginStatus(msg, 'back');
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _this = this;
	this.loginId = options.loginId
	this.user_options = {
        toLogin: true,
        showCancel: false,
        bg: false,
        refuseIsShow: true
    }
  },
  methods: {
    getUserInfo(e) {
      console.log('授权回调9999999999', e);

      if (e.userInfo) {
        _this.userInfo = e.userInfo;
        var msg = {
          desc: '小程序授权登录成功',
          ticket: wx.getStorageSync('ticket'),
          device_id: common.device_id,
          user: e.userInfo
        };
        reportLoginStatus(msg);
      }
    }
  }
};
</script>
<style>
	.userinfo-box .wrapper {
		background: #fff
	}
</style>
